/*
 * @Author: sjf 1758142861@qq.com
 * @Date: 2023-03-27 20:30:24
 * @LastEditors: sjf 1758142861@qq.com
 * @LastEditTime: 2023-03-31 18:32:21
 * @FilePath: /sjf/lwp/block_queue/again_test/test.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "forward_blockqueue.hpp"
#include <cstdlib>
#include <time.h>

void *_p(void *args)
{
    //Anwtie::BlockQueue<int>* queue = (Anwtie::BlockQueue<int>*)args;
    //const char* name = static_cast<const char*>(args);
    Anwtie::BlockQueue<int>* queue = static_cast<Anwtie::BlockQueue<int>*>(args);
    while(true)
    {
        sleep(1);
        int data = rand() % 1024;
        queue->push(data);
        std::cout << "_p->data:" << data << std::endl;
    }
    return nullptr;
    //pthread_exit((void*)0);
}

void* _c(void* args)
{
    Anwtie::BlockQueue<int>* queue = static_cast<Anwtie::BlockQueue<int>*>(args);
    while(true)
    {
        sleep(1);
        int data;
        queue->pop(&data);
        std::cout << "_c->data:" << data << std::endl; 
    }
    return nullptr;
}

int main()
{
    srand((unsigned int)time(nullptr));
    Anwtie::BlockQueue<int> *queue = new Anwtie::BlockQueue<int>;
    pthread_t p, c;
    pthread_create(&p, nullptr, _p, (void *)queue);
    pthread_create(&c, nullptr, _c, (void *)queue);

    pthread_join(p, nullptr);
    pthread_join(c, nullptr);
    delete queue;
    return 0;
}
